var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer')

var config = {
  your_mail: 'guoj@xinguangnet.com',
  mail_pass: '901221/Wang'
}

 var transporter = nodemailer.createTransport({
  host: "smtp.exmail.qq.com",//邮箱的服务器地址
  secure: true,
  port:465,
  auth: {
      user: config.your_mail,//邮箱账号
      pass: config.mail_pass,//邮箱密码
  }
})

var mailOptions = {
  from: config.your_mail, // 发件邮箱地址
  to: config.your_mail,// 收件邮箱地址，可以和发件邮箱一样
  // cc: 'lengxing@xinguangnet.com,ruibo@xinguangnet.com',
  cc: 'guojin200908623@163.com,577644988@qq.com',
  subject: '预约演示', // 邮件标题
  text: '', // 邮件内容
  html: '' // 邮件内容
}

/* 发送请求邮件到管理员邮箱 */
router.post('/', function(req, res, next) {
  var info = req.body
  // mailOptions.text = `姓名：${info.name}\n电话：${info.phone}\n公司名称：${info.company}\n公司邮箱：${info.email || '未填写'}\n微信：${info.WeChat || '未填写'}\n预约时间：${info.date}\n需求场景：${info.scene || '未填写'}\n了解渠道：${info.pipeline.join(',') || '未填写'}`
  mailOptions.html = `
                      <p>姓名：<span style='color:red;'>${info.name}</span></P>
                      <p>电话：<span style='color:red;'>${info.phone}</span></P>
                      <p>公司名称：<span style='color:red;'>${info.company}</span></P>
                      <p>公司邮箱：${info.email || '未填写'}</P>
                      <p>微信：${info.WeChat || '未填写'}</P>
                      <p>预约时间：<span style='color:red;'>${info.date}</span></P>
                      <p>需求场景：${info.scene || '未填写'}</P>
                      <p>了解渠道：${info.pipeline.join(',') || '未填写'}</P>
                     `
  // 发邮件部分
  transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    res.send({
      code: 200,
      message: '申请成功',
      success: true
    });
  });
});

module.exports = router;